﻿<cfscript>
/** 
* @hint "studentStatus - Student, StudentStatus"
*/ 

component 
	extends="MachII.framework.Listener" 
	displayname="acadmicManager.listeners.senate.studentListener" 
	output=false 
	depends="chineseFactory, sessionAdvice, stringAdvice, datetimeAdvice, studentPropertyAdvice,sequenceStudentSecondDegree,sequenceStudentSecondSubject,sequenceMatrixGroupUser,sequenceStudentChange,logFactory" 
	{
	
	/**
	* @hint "Configures this listener as part of the Mach-II framework"
	*/
	public void function configure() output=false {} 
	
	
	/**
	* @hint "学生学籍异动 - 外校学籍转入"
	* 
	* @event "MachII Event Object"
	*/
	public void function studentStatusCreate( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("StudentID");
		var changeType = event.getArg("ChangeTypeCode");
		var sql = "";
		var queryObj = "";
		
		var termId = event.getArg("TermID");
		
		/* 联合培养标志 */
		var isCooper= event.getArg("Cooperation");
		/* 进修生标志 */
		var isAdvanced= event.getArg("FurtherStudy");
		
		var tchId = getsessionAdvice().getAutherUserID();
		
		var propAdvice = getstudentPropertyAdvice().init();
		var chsFactory = getchineseFactory();
		
		var sequenceMatrixGroupUser = getsequenceMatrixGroupUser();
		var sequenceStudentChange = getsequenceStudentChange();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 学籍操作管理员 */
		
			/* 学籍异动类别 */
		
			/* 学籍异动学期 */
			
			/* 目标行政班 */
			
			sql = "SELECT b.subject_code,
						   a.grade,
						   b.level_code,
						   b.institute_id,
						   b.b_id,
						   a.cls_name,
						   a.cls_scale  
					FROM t_class a 
						 INNER JOIN t_subject b ON b.sbj_id = a.sbj_id 
					WHERE a.cls_id = :classId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="classId", value=classId, cfsqltype="cf_sql_char" );
			
			var rs_class = queryObj.execute( sql=sql ).getResult();
			
			/* 国家专业代码 */
			
			/* 籍贯 */
			
			/* 民族 */
			
			/* 学生类别 */
			
			/* 培养方式 */
			
			/* 证件类型 默认为身份证 */
		
			/* 政治面貌 默认为群众 */
			
			/* 第一步 学籍建档 */
			var StudentID =studentId; 
			var StudentName =event.getArg("StudentName"); 
			var Pinyin =chsFactory.getPinyinIndex( event.getArg("StudentName") ); 
			var EnglishName =chsFactory.getPinyin( event.getArg("StudentName") ); 
			var UsedName =event.getArg("UsedName"); 
			var Sex =event.getArg("Sex"); 
			var Birthday =replace(event.getArg("Birthday"), "-", "", "ALL"); 
			var IDCard =event.getArg("IDCard"); 
			var SubjectDirection ="0";  
			var FormClass =classId;
			var IDCardType ="01"; 
			var BirthPlace = event.getArg("AreaCode");
			var PoliticalStatus ="13";
			var Nation =event.getArg("NationCode");
			
			sql = "INSERT INTO t_student (
						 stu_id,
						 stu_name,
						 stu_pyidx,
						 stu_name_english,
						 stu_name_used,
						 stu_sex,
						 stu_birthday,
						 stu_idcard,
						 sbj_direction,
						 cls_id,
						 idtype,
						 area_code,
						 pa_code,
						 nation_code   
					) VALUES (
						:StudentID , 
						:StudentName ,
						:Pinyin ,
						:EnglishName ,
						:UsedName ,
						:Sex ,
						:Birthday ,
						:IDCard ,
						:SubjectDirection ,  
						:FormClass ,
						:IDCardType ,
						:BirthPlace ,
						:PoliticalStatus ,
						:Nation  
					)";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="StudentID", value=StudentID, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentName", value=StudentName, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Pinyin", value=Pinyin, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="EnglishName", value=EnglishName, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="UsedName", value=UsedName, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Sex", value=Sex, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="Birthday", value=Birthday, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="IDCard", value=IDCard, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="SubjectDirection", value=SubjectDirection, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="FormClass", value=FormClass, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="IDCardType", value=IDCardType, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="BirthPlace", value=BirthPlace, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="PoliticalStatus", value=PoliticalStatus, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="Nation", value=Nation, cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );
			
			/* 处理学籍数据 高考考生号默认为学号 */
			
			/* 处理学籍状态代码 */
			
			propAdvice.setRecognized( true ); /* 是否有学籍 */
			propAdvice.setRegister( true ); /* 是否电子注册 */
			propAdvice.setInSchool( true ); /* 是否在校 */
			var StudentCompany = "";
			if ( isCooper eq "1" ) {
				propAdvice.setRecognized( false );
				propAdvice.setRegister( false );
				propAdvice.setExchanged( true ); /* 交换生标记 */
				StudentCompany = event.getArg("Source") ; /* 记录联合培养学生所在学校 */
			}

			if ( isAdvanced eq "1" ) {
				propAdvice.setRecognized( false );
				propAdvice.setRegister( false );
				propAdvice.setAdvanced( true );  /* 进修生标记 */
				StudentCompany = event.getArg("Source") ; /* 记录进修生所在单位 */
			}
			
			sql = "INSERT INTO t_student_status(
						stu_id,
						acad_type,
						grade,
						level_code,
						status_code,
						candidatesno,
						date_join,
						homeaddr,
						zipcode,
						institute_id,
						subject_code,
						b_id,
						st_id,
						f_id,
						student_prop,
						stu_company
					) VALUES (
						:Student,
						:AcademicType,
						:Grade,
						:StudentLevel,
						:StatusCode,
						:CandidatesNo, 
						:JoinDate,
						:HomeAddress,
						:ZipCode,
						:Institute,
						:SubjectGB,
						:LearningBranch,
						:StudentType,
						:FosterType,
						:StudentProps,
						:StudentCompany  
					)";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="Student", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="AcademicType", value=event.getArg("AcademicType"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="Grade", value=rs_class.grade, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="StudentLevel", value=rs_class.level_code, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="StatusCode", value=event.getArg("StatusCode"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="CandidatesNo", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="JoinDate", value=replace(event.getArg("ApproveDate"), "-", "", "ALL"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="HomeAddress", value=event.getArg("HomeAddress"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="ZipCode", value=event.getArg("ZipCode"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Institute", value=rs_class.institute_id, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="SubjectGB", value=left(rs_class.subject_code, 6), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="LearningBranch", value=rs_class.b_id, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="StudentType", value=event.getArg("StudentTypeCode"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="FosterType", value=event.getArg("FosterCode"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="StudentProps", value= propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentCompany", value=StudentCompany, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			/* 处理学生成绩统计数据 */
			
			sql = "INSERT INTO t_student_profile 
							(
								stu_id, 
								credit, credit_req, credit_opt, credit_phy, credit_com, credit_failure,
								credit_req_pt, credit_req_avgpt, 
								credit_pt, credit_avgpt,
								subject_rank, subject_idx, 
								subject_rank_all, subject_idx_all, 
								credit_grad, credit_grad_pt, credit_grad_avgpt
							) 
							VALUES 
							(
								:studentId, 
								0, 0, 0, 0, 0, 0, 
								0, 0, 
								0, 0, 
								0, 0, 0, 0, 
								0, 0, 0
							) ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			/* 刷新行政班实际人数 */
			
			sql = "UPDATE t_class a 
					SET a.cls_scale = :RealSize 
					WHERE a.cls_id = :classId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="classId", value=classId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="RealSize", value=rs_class.cls_scale + 1, cfsqltype="cf_sql_integer" );
			
			queryObj.execute( sql=sql );
			
			/* 第二步 建立学生帐号 */
		
			sql = "INSERT INTO t_user (
						 user_id,
						 user_name,
						 user_email,
						 user_last_login,
						 user_last_login_ip  
					) VALUES (
							:UID,
							:Name,
							:Email,
							:LastTimeLogin,
							:LastTimeIP 
					)";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="UID", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Name", value=event.getArg("StudentName"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Email", value=studentId & "@email.unknown", cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="LastTimeLogin", value=getdatetimeAdvice().getCurrentDatetimeString(), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="LastTimeIP", value="127.0.0.1", cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			sequenceMatrixGroupUser.setUserId(studentId);
			sequenceMatrixGroupUser.setGroupId("P002");
			UserGroupID = sequenceMatrixGroupUser.getID();
			
			sql = "INSERT INTO t_groupuser (
						ugid,
						user_id,
						group_id,
						date_create,
						date_lastupdate
					) VALUES (
						:UserGroupID,
						:MatrixUser,
						:MatrixGroup,
						:Created,
						:LastUpdate	
					)";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="UserGroupID", value=UserGroupID, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="MatrixUser", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="MatrixGroup", value="P002", cfsqltype="cf_sql_char" );
			queryObj.addParam( name="Created", value=getdatetimeAdvice().getCurrentDatetimeString(), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="LastUpdate", value=getdatetimeAdvice().getCurrentDatetimeString(), cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );
			
			/* 第三步 生成学籍异动记录 */
	
			var docId = sequenceStudentChange.getID();
			var Description=event.getArg("Description");
			/* 根据学籍异动类别处理异动描述 */
			
			switch ( changeType ) {
				
				case "24":
					/* 专升本 */
					Description = " 自 " & event.getArg("Source") & " 专升本至 " & rs_class.cls_name ;
					break;
				
				case "22":
					/* 转学入 / 也用于 进修生 联合培养 */
					Description = " 自 " & event.getArg("Source") & " 转学至 " & rs_class.cls_name & " 跟班学习" ;
					
					if ( isCooper eq "1" ) {
						Description = event.getArg("Source") & " 联合培养学生，编入 " & rs_class.cls_name & " 跟班学习" ;
					}

					if ( isAdvanced eq "1" ) {
						Description = event.getArg("Source") & " 进修学生，编入 " & rs_class.cls_name & " 跟班学习";
					}
					
					break;
				
			}
			
			sql = "INSERT INTO t_stuchange (
						stuchg_id,
						change_date,
						approve_date,
						approve_docid,
						stu_source,
						stu_newlocation,
						op_description,
						institute_name,
						subject_name,
						grade,
						class_name,
						term_id,
						stu_id,
						admin_user_id,
						sct_code
					) VALUES(
						:ChangeID,
						:ChangeDate,
						:ApproveDate,
						:ApproveDocument,
						:Source,
						:Target,
						:Description,
						'',
						'',
						'',
						'',
						:Term,
						:Student,
						:Admin,
						:Type
					)";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="ChangeID", value=docId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="ChangeDate", value=getdatetimeAdvice().getCurrentDatetimeString(), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="ApproveDate", value=replace(event.getArg("ApproveDate"), "-", "", "ALL"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="ApproveDocument", value=event.getArg("ApproveDocument"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Source", value=event.getArg("Source"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Target", value=event.getArg("Target"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Description", value=Description, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Term", value=termId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="Student", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Admin", value=tchId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Type", value=changeType, cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );
			
			/* 参数传递 */
			event.setArg("STU", studentId);
			event.setArg("DOCID", docId);
			event.setArg("TID", termId);
			event.setArg("T", changeType);
			
		}
		
	}
	
	
	/**
	* @hint "学生学籍异动 - 学籍流出"
	* 
	* @event "MachII Event Object"
	*/
	public void function studentStatusSuspend( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("StudentID");
		var changeType = event.getArg("ChangeTypeCode");
		
		var termId = event.getArg("TermID");
		
		/* 联合培养标志 */
		var isCooper= event.getArg("Cooperation");
		
		var tchId = getsessionAdvice().getAutherUserID();
		
		var propAdvice = getstudentPropertyAdvice();
		
		var sql = "";
		var queryObj = ""; 
		
		var sequenceStudentChange = getsequenceStudentChange();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 学籍操作管理员 */
			
			/* 学生信息 */
			
			/* 学生学籍信息 */
		
			sql = "SELECT  b.student_prop,b.f_id,
							b.st_id,b.status_code,
							b.stu_company 
					FROM t_student a 
						 INNER JOIN t_student_status b ON b.stu_id = a.stu_id 
					WHERE a.stu_id = :studentId "; 
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype = "cf_sql_varchar");
	
			var rs_profile = queryObj.execute( sql=sql ).getResult();
			
			/* 行政班 */
		
			sql = "SELECT  b.cls_scale,b.cls_id 
					FROM t_student a 
						 INNER JOIN t_class b ON b.cls_id = a.cls_id 
					WHERE a.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype = "cf_sql_varchar");
	
			var rs_class = queryObj.execute( sql=sql ).getResult();
			
			/* 学籍异动类别 */
		
			/* 学籍异动学期 */
			
			/* 第一步 生成学籍异动记录 */
		
			/* 根据学籍异动类别处理异动描述 */
			var Description=event.getArg("Description");
			switch ( changeType ) {
				
				case "11":
					/* 休学 */
					Description = " 自 " & event.getArg("DateStart") & " 起开始休学，至 " & event.getArg("DateEnd");
					break;
				
				case "21":
					/* 转学出 / 也可以用于 公派 联合培养学生 */
					Description = " 自 " & event.getArg("Source") & " 转学至 " & event.getArg("StudentCompany");
					break;
				
			}
			
			var docId = sequenceStudentChange.getID(); 
			sql = "INSERT INTO t_stuchange  
					(
						 stuchg_id,
						 change_date,
						 approve_date,
						 approve_docid,
						 stu_source,
						 stu_newlocation,
						 op_description,
						 institute_name,
						 subject_name,
						 grade,
						 class_name,
						 term_id,
						 stu_id,
						 admin_user_id,
						 sct_code 
					) VALUES (
						:ChangeID,
						:ChangeDate,
						:ApproveDate,
						:ApproveDocument,
						:Source,
						:Target,
						:Description,
						:Institute,
						:Subject,
						:Grade,
						:FormClass,
						:Term,
						:Student,
						:Admin,
						:Type 	
					)";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="ChangeID", value=docId, cfsqltype = "cf_sql_char");
			queryObj.addParam( name="ChangeDate", value=getdatetimeAdvice().getCurrentDatetimeString(), cfsqltype = "cf_sql_char");
			queryObj.addParam( name="ApproveDate", value=replace(event.getArg("ApproveDate"), "-", "", "ALL"), cfsqltype = "cf_sql_char");
			queryObj.addParam( name="ApproveDocument", value=event.getArg("ApproveDocument"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Source", value=event.getArg("Source"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Target", value=event.getArg("Target"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Description", value=Description, cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Institute", value=event.getArg("Institute"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Subject", value=event.getArg("Subject"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Grade", value=event.getArg("Grade"), cfsqltype = "cf_sql_char");
			queryObj.addParam( name="FormClass", value=event.getArg("FormClass"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Term", value=termId, cfsqltype = "cf_sql_char");
			queryObj.addParam( name="Student", value=studentId, cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Admin", value=tchId, cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Type", value=changeType, cfsqltype = "cf_sql_char");
	
			queryObj.execute( sql=sql );
								
			/* 第二步 变更学生学籍状态 */
			
			/* 学生相关属性 */
			propAdvice.parseProperty( rs_profile.student_prop );
			
			/* 标注学生 不在校 */
			propAdvice.setInSchool( "0" );
			
			if ( changeType eq "32" ) {
				/* 如果学生退学 则取消学生学籍 */
				propAdvice.setRecognized( "0" );
			}
			var FosterType = rs_profile.f_id;
			var StudentType = rs_profile.st_id;
			
			var StudentProps = propAdvice.stringProperty();
			var StatusCode = rs_profile.status_code;
			var StudentCompany = rs_profile.stu_company;
			/* 变更学籍状态 */
			
			/* 11-休学  标注学籍状态为 02-休学 */
			if ( changeType eq "11" ) {
				StatusCode = "02";
			}
			/* 32-退学  标注学籍状态为 03-退学 */
			if ( changeType eq "32" ) {
				StatusCode = "03";
			}
			/* 21-转学出  标注学籍状态为 10-转学（转出） */
			if ( changeType eq "21" ) {
				StatusCode = "10";
				StudentCompany = event.getArg("StudentCompany");
			}
			
			sql = "UPDATE t_student_status b
					SET     b.student_prop = :StudentProps ,
							b.status_code = :StatusCode ,
							b.stu_company = :StudentCompany   
					WHERE b.stu_id = :studentId "; 
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="StudentProps", value=StudentProps, cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="StatusCode", value=StatusCode, cfsqltype = "cf_sql_char");
			queryObj.addParam( name="StudentCompany", value=StudentCompany, cfsqltype = "cf_sql_varchar");
	
			queryObj.execute( sql=sql );
			
			/* 刷新行政班实际人数 */
			
		
			
			/* 参数传递 */
			event.setArg("STU", studentId);
			event.setArg("DOCID", docId);
			event.setArg("TID", termId);
			event.setArg("T", changeType);
			
				
		}
		
	}

	/**
	* @hint "学生学籍异动 - 校内变更"
	* 
	* @event "MachII Event Object"
	*/
	public void function studentStatusModify( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("StudentID");
		var classId = event.getArg("ClassID");
		var changeType = event.getArg("ChangeTypeCode");
		
		var termId = event.getArg("TermID");
		
		var tchId = getsessionAdvice().getAutherUserID();
		
		var propAdvice = getstudentPropertyAdvice();
		
		var sql = "";
		var queryObj = "";
		var sequenceStudentChange = getsequenceStudentChange();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 学籍操作管理员 */
			
			/* 学生信息 */
		
			/* 学生学籍信息 */
		
			sql = "SELECT b.student_prop,
						   b.grade,
						   b.level_code,
						   b.status_code
					FROM t_student a 
						 INNER JOIN t_student_status b ON b.stu_id = a.stu_id 
					WHERE a.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_studentProfile = queryObj.execute( sql=sql ).getResult();
			
			/* 目标行政班 */
	
			sql = "SELECT a.grade,
						   b.level_code,  
						   a.cls_scale 
					FROM t_class a 
						 INNER JOIN t_subject b ON b.sbj_id = a.sbj_id 
					WHERE a.cls_id = :classId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="classId", value=classId, cfsqltype="cf_sql_char" );
			
			var rs_class = queryObj.execute( sql=sql ).getResult();
			/* 原行政班 */
	
			sql = "SELECT b.cls_scale,b.cls_id  
					FROM t_student a 
						 INNER JOIN t_class b ON b.cls_id = a.cls_id 
					WHERE a.stu_id = :studentId ";
				
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_classOld = queryObj.execute( sql=sql ).getResult();
			
			
			/* 学籍异动类别 */
		
			/* 学籍异动学期 */
		
			/* 第一步 生成学籍异动记录 */
	
			var docId = sequenceStudentChange.getID();
			
			sql = "INSERT INTO t_stuchange  
					(
						 stuchg_id,
						 change_date,
						 approve_date,
						 approve_docid,
						 stu_source,
						 stu_newlocation,
						 op_description,
						 institute_name,
						 subject_name,
						 grade,
						 class_name,
						 term_id,
						 stu_id,
						 admin_user_id,
						 sct_code 
					) VALUES (
						:ChangeID,
						:ChangeDate,
						:ApproveDate,
						:ApproveDocument,
						:Source,
						:Target,
						:Description,
						:Institute,
						:Subject,
						:Grade,
						:FormClass,
						:Term,
						:Student,
						:Admin,
						:Type 	
					)";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="ChangeID", value=docId, cfsqltype = "cf_sql_char");
			queryObj.addParam( name="ChangeDate", value=getdatetimeAdvice().getCurrentDatetimeString(), cfsqltype = "cf_sql_char");
			queryObj.addParam( name="ApproveDate", value=replace(event.getArg("ApproveDate"), "-", "", "ALL"), cfsqltype = "cf_sql_char");
			queryObj.addParam( name="ApproveDocument", value=event.getArg("ApproveDocument"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Source", value=event.getArg("Source"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Target", value=event.getArg("Target"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Description", value=event.getArg("Description"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Institute", value=event.getArg("Institute"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Subject", value=event.getArg("Subject"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Grade", value=event.getArg("Grade"), cfsqltype = "cf_sql_char");
			queryObj.addParam( name="FormClass", value=event.getArg("FormClass"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Term", value=termId, cfsqltype = "cf_sql_char");
			queryObj.addParam( name="Student", value=studentId, cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Admin", value=tchId, cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="Type", value=changeType, cfsqltype = "cf_sql_char");
	
			queryObj.execute( sql=sql );
			
			/* 第二步 变更学生注册班级信息 */
			
			/* 第三步 变更学生学籍状态 */
			
			/* 学生相关属性 */
			propAdvice.parseProperty( rs_studentProfile.student_prop );
			
			/* 根据学籍异动类别 设置学生是否在校 */
			/* 03-降级  12-复学  23-转专业 */
			if ( changeType eq "03" or changeType eq "12" or changeType eq "23" ) {
				propAdvice.setInSchool( "1" );
			}

			var StudentProps = propAdvice.stringProperty();

			var Grade = rs_class.grade;
			var StudentLevel = rs_class.level_code;
			
			var StatusCode = rs_studentProfile.status_code;
			
			/* 03-降级  23-转专业 标注学籍状态为 01-在读 */
			if ( changeType eq "03" or changeType eq "23" ) {
				StatusCode = "01";
			}
			/* 12-复学  标注学籍状态为 05-复学 */
			if ( changeType eq "12" ) {
				StatusCode = "05" ;
			}
			
			sql = "UPDATE t_student_status b
					SET    b.student_prop = :StudentProps,
						   b.status_code = :StatusCode 
					WHERE b.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentProps", value=StudentProps, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StatusCode", value=StatusCode, cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );
			
			/* 刷新行政班实际人数 */
		
			/* 参数传递 */
			event.setArg("STU", studentId);
			event.setArg("DOCID", docId);
			event.setArg("TID", termId);
			event.setArg("T", changeType);

		}
		
	}


	/**
	* @hint "批量删除学生档案"
	* 
	* @event "MachII Event Object"
	*/
	public void function cleanStudentProfile( required MachII.framework.Event event ) output=false {
		
		var studentIds = listToArray(event.getArg("StudentIDs"), ", " & chr(10) & chr(13));
		
		var sql = ""; 
		var queryObj = ""; 
		/* Every SQL operation is TRANSACATION*/
		transaction {
				
			for ( var studentId in studentIds ) {
				
				sql = "DELETE FROM t_student WHERE stu_id = :studentId "; 
				
				queryObj = new Query( datasource=application.dnsMaster ); 
				queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				
				queryObj.execute( sql=sql );

				/* 删除用户帐号及相应授权 */
				sql = "DELETE FROM t_user WHERE user_id = :userId "; 
				
				queryObj = new Query( datasource=application.dnsMaster ); 
				queryObj.addParam( name="userId", value=studentId, cfsqltype="cf_sql_varchar" );
				
				queryObj.execute( sql=sql );

			}
				
		}
		
	}
	/**
	* @hint "根据身份证号批量删除学生档案"
	* 
	* @event "MachII Event Object"
	*/
	public void function cleanIDCardStudentProfile( required MachII.framework.Event event ) output=false {
		
		var IDCards = listToArray(event.getArg("IDCards"), ", " & chr(10) & chr(13));
		
		var sql = ""; 
		var queryObj = ""; 
		studentId = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
				
			for ( var IDCard in IDCards ) {
				
				sql = "SELECT stu_id FROM t_student WHERE stu_idcard = :idCard "; 
				
				queryObj = new Query( datasource=application.dnsMaster ); 
				queryObj.addParam( name="idCard", value=IDCard, cfsqltype="cf_sql_varchar" );
				
				var rs_student = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_student.recordCount ) {
				    studentId = rs_student.stu_id;
			
					sql = "DELETE FROM t_student WHERE stu_id = :studentId "; 
				
					queryObj = new Query( datasource=application.dnsMaster ); 
					queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
	
					/* 删除用户帐号及相应授权 */
					sql = "DELETE FROM t_user WHERE user_id = :userId "; 
					
					queryObj = new Query( datasource=application.dnsMaster ); 
					queryObj.addParam( name="userId", value=studentId, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}

			}
				
		}
		
	}
	
	
	/**
	* @hint "学生自己更新联系信息"
	* 
	* @event "MachII Event Object"
	*/
	public void function updateStudentContract( required MachII.framework.Event event ) output=false {
		
		var studentId = getsessionAdvice().getAutherUserID();
			
		var sql = ""; 
		var queryObj = ""; 

		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "SELECT 
						 a.stu_name, 
						 a.stu_name_english,
						 a.stu_sex, 
						 a.stu_idcard, 
						 a.stu_birthday, 
						 a.nationality, 
						 a.continent, 
						 b.homeaddr, 
						 b.ch_addr,
						 b.pt_date, 
						 b.date_join,
						 b.is_married,
						 b.f_id, 
						 b.stu_email, 
						 b.stu_tel 
					FROM 
						 t_student a, t_student_status b 
					WHERE 
						 b.stu_id = a.stu_id 
						 AND 
						 a.stu_id = :studentId "; 
			
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_student = queryObj.execute( sql=sql ).getResult();
			
			var studentName = trim( rs_student.stu_name );
			var englishName = trim( rs_student.stu_name_english );
			var idCard = trim( rs_student.stu_idcard );
			var ptDate = trim( rs_student.pt_date );//护照有效期
			var birthday = trim( rs_student.stu_birthday );
			var dateJoin = trim( rs_student.date_join );
			var sex = rs_student.stu_sex ;
			var isMarried = trim( rs_student.is_married );
			var nationality = trim( rs_student.nationality );
			var continent = trim( rs_student.continent );
			var funds = trim( rs_student.f_id  );
			var email = trim( rs_student.stu_email );
			var tel = trim( rs_student.stu_tel );
			var homeAddr = trim( rs_student.homeaddr );
			var chAddr = trim( rs_student.ch_addr );
			

			var content = ""; //日志
			
			var studentName_temp = trim( event.getArg("StudentName"));
			if ( event.isArgDefined("StudentName") and (studentName_temp neq studentName) ) {
				studentName = studentName_temp;
				content = content & "中文名由 " & rs_student.stu_name & " 修改为 " & studentName & " ;";
			}
			
			var englishName_temp = trim(event.getArg("englishName"));
			if ( event.isArgDefined("englishName") and (englishName_temp neq englishName) ) { 
				englishName = englishName_temp;
				content = content & "护照名由 " & rs_student.stu_name_english & " 修改为 " & englishName & " ;";
			}
			
			var idCard_temp = trim(event.getArg("IDCard"));
			if ( event.isArgDefined("IDCard") and (idCard_temp neq idCard) ) {
				idCard = idCard_temp;
				content = content & "护照号由 " & rs_student.stu_idcard & " 修改为 " & idCard_temp & " ;";
			}
			
			
			if ( event.isArgDefined("Sex") and (event.getArg("Sex") NEQ sex) ) { 
				sex = event.getArg("Sex");
				content = content & "性别由 " & rs_student.stu_sex & " 修改为 " & sex & " ;";
			}
				
			if ( event.isArgDefined("emailAddress") and (event.getArg("emailAddress") NEQ email) ) { 
				email = event.getArg("emailAddress");
			}
			
			if ( event.isArgDefined("telephone") and (event.getArg("telephone") NEQ tel) ) { 
				tel = event.getArg("telephone");
			}
			
			if ( event.isArgDefined("homeAddr") and (event.getArg("homeAddr") NEQ homeAddr) ) { 
				homeAddr = event.getArg("homeAddr");
			}
			
			if ( event.isArgDefined("chAddr") and (event.getArg("chAddr") NEQ chAddr) ) { 
				chAddr = event.getArg("chAddr");
			}
			
			sql = "UPDATE t_student SET 
						 stu_name = :studentName, 
						 stu_name_english = :englishName, 
						 stu_sex = :sex, 
						 stu_idcard = :idCard 
					WHERE 
						 stu_id = :studentId "; 
	
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="studentName", value=studentName, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="englishName", value=englishName, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="sex", value=sex, cfsqltype="cf_sql_char" ); 
			queryObj.addParam( name="idCard", value=idCard, cfsqltype="cf_sql_varchar" ); 
			
			queryObj.execute( sql=sql );
			
			sql = "UPDATE t_student_status SET 
						  homeaddr = :homeAddress, 
						  stu_email = :email, 
						  stu_tel = :tel,
						  ch_addr = :chAddr 
					WHERE 
						  stu_id = :studentId "; 
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="homeAddress", value=homeAddr, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="email", value=email, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="tel", value=tel, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="chAddr", value=chAddr, cfsqltype="cf_sql_varchar" ); 
			
			queryObj.execute( sql=sql );
			
			sql = "UPDATE t_user t SET t.user_name = :userName, t.user_email = :email WHERE user_id = :userId"; 
			
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="userId", value=studentId, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="email", value=email, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="userName", value=studentName, cfsqltype="cf_sql_varchar" ); 
			
			queryObj.execute( sql=sql );
			
			var password = trim( event.getArg("password") );
			
			if( password neq ""){
				sql = "UPDATE t_user
						SET 
							user_pass = :userPass 
						WHERE 
							user_id = :studentId ";
	
				queryObj = new Query( datasource=application.dnsMaster );
				
				queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
	
				queryObj.addParam( name="userPass", value=password, cfsqltype="cf_sql_varchar" );
	
				queryObj.execute( sql=sql );
			}
			
			if( content neq "" ){
				logFactory.writeLog("5",content,studentId);
			}

			event.setArg( "UserName", studentName );
		}
		
		
	}
	
	/**
	* @hint "更新学生学籍状态信息"
	* 
	* @event "MachII Event Object"
	*/
	public void function updateStudentStatus( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("StudentID");
		
		var propAdvice = getstudentPropertyAdvice();
		
		var sql = ""; 
		var queryObj = ""; 
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 学生信息 */
			/* 学生学籍信息 */
			sql = "SELECT 
						 b.st_id, 
						 b.student_prop,
						 b.is_bachelor,
						 b.status_code, 
						 b.hsk_score,
						 b.hsk_date,
						 b.is_noexam 
					FROM 
						 t_student_status b 
					WHERE 
						 b.stu_id = :studentId "; 
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_student = queryObj.execute( sql=sql ).getResult();
			
			var studentTypeCode = rs_student.st_id;
			var studentProps = rs_student.student_prop;
			var isBachelor = rs_student.is_bachelor;
			var statusCode = rs_student.status_code;
			var hskScore = rs_student.hsk_score;
			var hskDate = rs_student.hsk_date;
			var isNoExam = rs_student.is_noexam;
			
			
			sql = "SELECT 1 FROM i_code_info WHERE code_id = :studentTypeCode"; 
				
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentTypeCode", value=event.getArg("StudentTypeCode"), cfsqltype="cf_sql_char" ); 
			
			var rs_studentType = queryObj.execute( sql=sql ).getResult();
				
			var content = "";
			
			if ( rs_studentType.recordCount ) {
				
				if( studentTypeCode NEQ event.getArg("StudentTypeCode")){
					
					content = content & "学生类型由 " & studentTypeCode & " 修改为 " & event.getArg("StudentTypeCode") & " ;";	
					
				}
				
				studentTypeCode = event.getArg("StudentTypeCode");
				
			}
			if( statusCode NEQ event.getArg("StatusCode")){
				 
				 content = content & "学籍状态由 " & statusCode & " 修改为 " & event.getArg("StatusCode") & " ;";	
				 
			 }
			 
			 statusCode = event.getArg("StatusCode") ;
			 
			 if( hskScore NEQ event.getArg("HSK")){
				 
				 content = content & "HSK成绩由 " & hskScore & " 修改为 " & event.getArg("HSK") & " ;";	
				 
			 }
			 
			 hskScore = event.getArg("HSK");
			 
			  if( hskDate NEQ event.getArg("hskDate")){
				 
				 content = content & "HSK通过时间由 " & hskDate & " 修改为 " & event.getArg("hskDate") & " ;";	
				 
			 }
			 
			 hskDate = event.getArg("hskDate");
			 
			  if( isNoExam NEQ event.getArg("isNoExam")){
				 
				 content = content & "是否免修由 " & isNoExam & " 修改为 " & event.getArg("isNoExam") & " ;";	
				 
			 }
			 
			 isNoExam = event.getArg("isNoExam");
			
			if( studentTypeCode eq '8'){
				isBachelor = "1";	
			}else{
				isBachelor = "0";	
			}
		
			/* 学生相关属性 */
			propAdvice.parseProperty( studentProps );
			
			if( propAdvice.getInSchool() NEQ event.getArg("InSchool", 0) ){
				content = content & "是否在校修改为 " & event.getArg("InSchool", 0) & " ;";	
			}
			
			if( propAdvice.getRecognized() NEQ event.getArg("Recognized", 0) ){
				content = content & "是否有学籍修改为 " & event.getArg("Recognized", 0) & " ;";	
			}
			
			if( propAdvice.getRegister() NEQ event.getArg("Register", 0) ){
				content = content & "是否电子注册修改为 " & event.getArg("Register", 0) & " ;";	
			}
			
			if( propAdvice.getNonresident() NEQ event.getArg("Nonresident", 0) ){
				content = content & "是否走读生修改为 " & event.getArg("Nonresident", 0) & " ;";	
			}
			
			if( propAdvice.getAbroad() NEQ event.getArg("Abroad", 0) ){
				content = content & "是否留学生修改为 " & event.getArg("Abroad", 0) & " ;";	
			}
			
			if( propAdvice.getExchanged() NEQ event.getArg("Exchanged", 0) ){
				content = content & "是否交换生修改为 " & event.getArg("Exchanged", 0) & " ;";	
			}
			
			propAdvice.setInSchool( event.getArg("InSchool", 0) );
			propAdvice.setRecognized( event.getArg("Recognized", 0) );
			propAdvice.setRegister( event.getArg("Register", 0) );
			propAdvice.setNonresident( event.getArg("Nonresident", 0) );
			propAdvice.setAbroad( event.getArg("Abroad", 0) );
			propAdvice.setExchanged( event.getArg("Exchanged", 0) );
			
			/* 01-在读 05-复学 */
			if ( ( event.getArg("StatusCode") eq "01" or event.getArg("StatusCode") eq "05" ) ) {
				propAdvice.setInSchool( "1" );
			}
			else {
				/* 学生不在校 */
				propAdvice.setInSchool( "0" );
			}
			
			/* 10-转学（转出） 11-死亡 14-开除 */
			if ( event.getArg("StatusCode") eq "10" or event.getArg("StatusCode") eq "11" or event.getArg("StatusCode") eq "14" ) {
				/* 取消学生学籍 */
				propAdvice.setRecognized( "0" );
			}
			
			studentProps = propAdvice.stringProperty();
			
			
			sql = "UPDATE t_student_status SET 
						  status_code = :statusCode, 
						  st_id = :studentTypeCode, 
						  student_prop = :studentProps,
						  is_bachelor = :isBachelor,
						  hsk_score = :hskScore,
						  hsk_date = :hskDate, 
						  is_noexam = :isNoExam 
					WHERE 
						  stu_id = :studentId "; 
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="statusCode", value=statusCode, cfsqltype="cf_sql_char" ); 
			queryObj.addParam( name="studentTypeCode", value=studentTypeCode, cfsqltype="cf_sql_char" ); 
			queryObj.addParam( name="studentProps", value=studentProps, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="isBachelor", value=isBachelor, cfsqltype="cf_sql_char" ); 
			queryObj.addParam( name="hskScore", value=hskScore, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="hskDate", value=hskDate, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="isNoExam", value=isNoExam, cfsqltype="cf_sql_char" ); 
			
			queryObj.execute( sql=sql );
			
			if( content neq "" ){
				logFactory.writeLog("6",content,studentId);
			}
			
			event.setArg("STU", studentId);
			event.setArg("OP", "status");
			event.setArg("CLASS", event.getArg("CLASS"));

			if ( event.isArgDefined("targetTab") ) {
				event.setArg("TabID", event.getArg("targetTab"));
			}
			
		}
	}
	
	/**
	* @hint "更新学生学籍信息"
	* 
	* @event "MachII Event Object"
	*/
	public void function updateStudentProfile( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("StudentID");
				
		var sql = ""; 
		var queryObj = ""; 

		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "SELECT 
						 a.stu_name, 
						 a.stu_name_english,
						 a.stu_sex, 
						 a.stu_idcard, 
						 a.stu_birthday, 
						 a.nationality, 
						 a.continent, 
						 b.homeaddr, 
						 b.ch_addr,
						 b.pt_date, 
						 b.date_join,
						 b.is_married,
						 b.f_id, 
						 b.stu_email, 
						 b.stu_tel 
					FROM 
						 t_student a, t_student_status b 
					WHERE 
						 b.stu_id = a.stu_id 
						 AND 
						 a.stu_id = :studentId "; 
			
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_student = queryObj.execute( sql=sql ).getResult();
			
			var studentName = trim( rs_student.stu_name );
			var englishName = trim( rs_student.stu_name_english );
			var idCard = trim( rs_student.stu_idcard );
			var ptDate = trim( rs_student.pt_date );//护照有效期
			var birthday = trim( rs_student.stu_birthday );
			var dateJoin = trim( rs_student.date_join );
			var sex = rs_student.stu_sex ;
			var isMarried = trim( rs_student.is_married );
			var nationality = trim( rs_student.nationality );
			var continent = trim( rs_student.continent );
			var funds = trim( rs_student.f_id  );
			var email = trim( rs_student.stu_email );
			var tel = trim( rs_student.stu_tel );
			var homeAddr = trim( rs_student.homeaddr );
			var chAddr = trim( rs_student.ch_addr );
			

			var content = ""; //日志
			
			var studentName_temp = trim( event.getArg("StudentName"));
			if ( event.isArgDefined("StudentName") and (studentName_temp neq studentName) ) {
				studentName = studentName_temp;
				content = content & "中文名由 " & rs_student.stu_name & " 修改为 " & studentName & " ;";
			}
			
			var englishName_temp = trim(event.getArg("englishName"));
			if ( event.isArgDefined("englishName") and (englishName_temp neq englishName) ) { 
				englishName = englishName_temp;
				content = content & "护照名由 " & rs_student.stu_name_english & " 修改为 " & englishName & " ;";
			}
			
			var idCard_temp = trim(event.getArg("IDCard"));
			if ( event.isArgDefined("IDCard") and (idCard_temp neq idCard) ) {
				idCard = idCard_temp;
				content = content & "护照号由 " & rs_student.stu_idcard & " 修改为 " & idCard_temp & " ;";
			}
			
			var ptDate_temp = trim(event.getArg("ptDate"));

			
			if ( event.isArgDefined("ptDate") and (ptDate_temp neq ptDate) ) {
				
				content = content & "护照有效期由 " & rs_student.pt_date & " 修改为 " & ptDate_temp & " ;";
			}
			
			ptDate = ptDate_temp;
			
			var birthday_temp = trim(event.getArg("Birthday"));
			
			if ( event.isArgDefined("Birthday") and (birthday_temp neq birthday) ) {
				
				content = content & "出生日期由 " & rs_student.stu_birthday & " 修改为 " & birthday_temp & " ;";
			}
			birthday = birthday_temp;
			
			var dateJoin_temp = trim(event.getArg("dateJoin"));
			if ( event.isArgDefined("dateJoin") and (dateJoin_temp neq dateJoin) ) {
				
				content = content & "入学时间由 " & rs_student.date_join & " 修改为 " & dateJoin_temp & " ;";
			}
			dateJoin = dateJoin_temp;
			
			
			if ( event.isArgDefined("Sex") and (event.getArg("Sex") NEQ sex) ) { 
				sex = event.getArg("Sex");
				content = content & "性别由 " & rs_student.stu_sex & " 修改为 " & sex & " ;";
			}
			
			if ( event.isArgDefined("isMarried") ) { 
				isMarried = event.getArg("isMarried");
			}
			
			if ( event.isArgDefined("countryName") and (event.getArg("countryName") NEQ nationality) ) { 
				nationality = event.getArg("countryName");
				content = content & "国家由 " & rs_student.nationality & " 修改为 " & nationality & " ;";
			}
			
			if ( event.isArgDefined("continent") and (event.getArg("continent") NEQ continent) ) { 
				continent = event.getArg("continent");
			}
			
			if ( event.isArgDefined("funds") and (event.getArg("funds") NEQ funds) ) { 
				funds = event.getArg("funds");
				content = content & "经费来源由 " & rs_student.f_id & " 修改为 " & funds & " ;";
			}
			
			if ( event.isArgDefined("emailAddress") and (event.getArg("emailAddress") NEQ email) ) { 
				email = event.getArg("emailAddress");
			}
			
			if ( event.isArgDefined("telephone") and (event.getArg("telephone") NEQ tel) ) { 
				tel = event.getArg("telephone");
			}
			
			if ( event.isArgDefined("homeAddr") and (event.getArg("homeAddr") NEQ homeAddr) ) { 
				homeAddr = event.getArg("homeAddr");
			}
			
			if ( event.isArgDefined("chAddr") and (event.getArg("chAddr") NEQ chAddr) ) { 
				chAddr = event.getArg("chAddr");
			}
			
			sql = "UPDATE t_student SET 
						 stu_name = :studentName, 
						 stu_name_english = :englishName, 
						 stu_sex = :sex, 
						 stu_idcard = :idCard, 
						 stu_birthday = :birthday,
						 nationality = :nationality, 
						 continent = :continent 
					WHERE 
						 stu_id = :studentId "; 
	
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="studentName", value=studentName, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="englishName", value=englishName, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="sex", value=sex, cfsqltype="cf_sql_char" ); 
			queryObj.addParam( name="idCard", value=idCard, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="birthday", value=birthday, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="nationality", value=nationality, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="continent", value=continent, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			sql = "UPDATE t_student_status SET 
						  f_id = :funds,
						  date_join = :dateJoin, 
						  homeaddr = :homeAddress, 
						  stu_email = :email, 
						  stu_tel = :tel,
						  is_married = :isMarried,
						  ch_addr = :chAddr, 
						  pt_date = :ptDate 
					WHERE 
						  stu_id = :studentId "; 
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="funds", value=funds, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="dateJoin", value=dateJoin, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="homeAddress", value=homeAddr, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="email", value=email, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="tel", value=tel, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="isMarried", value=isMarried, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="chAddr", value=chAddr, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="ptDate", value=ptDate, cfsqltype="cf_sql_varchar" ); 
			
			queryObj.execute( sql=sql );
			
			sql = "UPDATE t_user t SET t.user_name = :userName, t.user_email = :email WHERE user_id = :userId"; 
			
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="userId", value=studentId, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="email", value=email, cfsqltype="cf_sql_varchar" ); 
			queryObj.addParam( name="userName", value=studentName, cfsqltype="cf_sql_varchar" ); 
			
			queryObj.execute( sql=sql );
			
			if( content neq "" ){
				logFactory.writeLog("5",content,studentId);
			}

			event.setArg("STU", studentId);
			event.setArg("OP", "profile");
			event.setArg("class", event.getArg("class"));

			if ( event.isArgDefined("targetTab") ) {
				event.setArg("TabID", event.getArg("targetTab"));
			}

		}
		
		
		
	}
	
	
	/**
	* @hint "设置在校学生的双学位专业信息及双学位选课授权"
	* 
	* @event "MachII Event Object"
	*/
	public void function addStudentSecondDegree( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("studentId");
		
		var subjectId = event.getArg("subjectId");
		var grade = event.getArg("Grade");
		var subjectDir = event.getArg("SubjectDirection");
		var sql = "";
		var queryObj = "";
		var sequenceStudentSecondDegree = getsequenceStudentSecondDegree();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sequenceStudentSecondDegree.setGrade(grade);
			var nextId = sequenceStudentSecondDegree.getID();
			
			var Grade = grade ; 
			var SubjectDirection = subjectDir ;
			var Credit = 0 ;
			var TimeSignedUp = replace(event.getArg("TimeSignedUp"), "-", "", "ALL") ;
			var TimeReviewed = replace(event.getArg("TimeReviewed"), "-", "", "ALL");
			var CurrentStat = event.getArg("CurrentStat") ;
			var Subject = subjectId ;
			var SecDegreeID = nextId ;
			var Student = studentId ;
			
			sql = "INSERT INTO t_student_secdegree (
						stusec_id,
						grade,
						sbj_direction,
						credit,
						signedup,
						reviewed,
						stat,
						sbj_id,
						stu_id
					) VALUES (
						:SecDegreeID ,
						:Grade ,
						:SubjectDirection ,
						:Credit ,
						:TimeSignedUp ,
						:TimeReviewed ,
						:CurrentStat ,
						:Subject ,
						:Student 
					)";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="SecDegreeID", value=SecDegreeID, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Grade", value=Grade, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="SubjectDirection", value=SubjectDirection, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="Credit", value=Credit, cfsqltype="cf_sql_decimal", scale =2 );
			queryObj.addParam( name="TimeSignedUp", value=TimeSignedUp, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="TimeReviewed", value=TimeReviewed, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="CurrentStat", value=CurrentStat, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="Subject", value=Subject, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Student", value=Student, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			/* 学生双学位选课授权*/
			var propAdvice = getstudentPropertyAdvice().init();
		
			sql = "SELECT a.student_prop
					FROM t_student_status a 
					WHERE a.stu_id = :studentId ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_studentProfile = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty( rs_studentProfile.student_prop );
			
			propAdvice.setSecondary( true );
			
			sql = "UPDATE t_student_status a
					SET a.student_prop = :StudentProps 
					WHERE a.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentProps", value= propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );

		}

	}
	
	
	/**
	* @hint "设置在校学生的辅修专业信息及辅修选课授权"
	* 
	* @event "MachII Event Object"
	*/
	public void function addAssistSubject( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("studentId");
		
		var subjectId = event.getArg("subjectId");
		var grade = event.getArg("Grade");
		var subjectDir = event.getArg("SubjectDirection");
		var sql = "";
		var queryObj = "";
		
		var sequenceStudentSecondSubject = getsequenceStudentSecondSubject();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sequenceStudentSecondSubject.setGrade(grade);
			var nextId = sequenceStudentSecondSubject.getID();
			
			var Grade = grade ; 
			var SubjectDirection = subjectDir ;
			var Credit = 0 ;
			var TimeSignedUp = replace(event.getArg("TimeSignedUp"), "-", "", "ALL") ;
			var TimeReviewed = replace(event.getArg("TimeReviewed"), "-", "", "ALL") ;
			var CurrentStat = event.getArg("CurrentStat");
			var Subject = subjectId ;
			var AssitSubjectID = nextId ;
			var Student = studentId ;
			
			sql = "INSERT INTO t_student_secsubject (
						stusec_id,
						grade,
						sbj_direction,
						credit,
						signedup,
						reviewed,
						stat,
						sbj_id,
						stu_id
					) VALUES (
						:AssitSubjectID ,
						:Grade ,
						:SubjectDirection ,
						:Credit ,
						:TimeSignedUp ,
						:TimeReviewed ,
						:CurrentStat ,
						:Subject ,
						:Student 
					)";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="AssitSubjectID", value=AssitSubjectID, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Grade", value=Grade, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="SubjectDirection", value=SubjectDirection, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="Credit", value=Credit, cfsqltype="cf_sql_decimal", scale =2 );
			queryObj.addParam( name="TimeSignedUp", value=TimeSignedUp, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="TimeReviewed", value=TimeReviewed, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="CurrentStat", value=CurrentStat, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="Subject", value=Subject, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="Student", value=Student, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			/* 学生辅修选课授权*/
			var propAdvice = getstudentPropertyAdvice().init();
			
			sql = "SELECT a.student_prop
					FROM t_student_status a 
					WHERE a.stu_id = :studentId ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_studentProfile = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty( rs_studentProfile.student_prop );
			
			propAdvice.setAssist( true );
			
			sql = "UPDATE t_student_status a
					SET a.student_prop = :StudentProps 
					WHERE a.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentProps", value= propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );

		}
		
	}
	

	/**
	* @hint "终止辅修修读资格"
	* 
	* @event "MachII Event Object"
	*/
	public void function stopAssistSubject( required MachII.framework.Event event ) output=false {

		var studentId = event.getArg("STU");
		var studentAccessId = event.getArg("STUGRT");
		var sql = "";
		var queryObj = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			
			/* 取消学生辅修选课授权*/
			
			sql = "UPDATE t_student_secsubject 
					SET stat = :CurrentStat 
					WHERE stusec_id = :studentAccessId ";
					
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentAccessId", value=studentAccessId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="CurrentStat", value="0", cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );
			
			var propAdvice = getstudentPropertyAdvice().init();
			
			sql = "SELECT a.student_prop
					FROM t_student_status a 
					WHERE a.stu_id = :studentId ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_studentProfile = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty( rs_studentProfile.student_prop );
			
			propAdvice.setAssist( false );
		
			sql = "UPDATE t_student_status a
					SET a.student_prop = :StudentProps 
					WHERE a.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentProps", value= propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );

		}

	}
	
	/**
	* @hint "取消辅修修读资格"
	* 
	* @event "MachII Event Object"
	*/
	public void function clearAssistSubject( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("STU");
		var studentAccessId = event.getArg("STUGRT");
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "DELETE 
					FROM t_student_secsubject a 
					WHERE a.stusec_id = :studentAccessId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentAccessId", value=studentAccessId, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			
			var propAdvice = getstudentPropertyAdvice().init();
		
			sql = "SELECT a.student_prop
					FROM t_student_status a 
					WHERE a.stu_id = :studentId ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_studentProfile = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty( rs_studentProfile.student_prop );
			
			propAdvice.setAssist( false );
			
			sql = "UPDATE t_student_status a
					SET a.student_prop = :StudentProps 
					WHERE a.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentProps", value= propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
		}
		
	}

	/**
	* @hint "恢复学生辅修资格"
	* 
	* @event "MachII Event Object"
	*/
	public void function openAssistSubject( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("STU");
		var studentAccessId = event.getArg("STUGRT");
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
		
			/* 恢复学生辅修选课授权*/
		
			sql = "UPDATE t_student_secsubject 
					SET stat = :CurrentStat 
					WHERE stusec_id = :studentAccessId ";
					
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentAccessId", value=studentAccessId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="CurrentStat", value="1", cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );
			
			
			var propAdvice = getstudentPropertyAdvice().init();
		
			sql = "SELECT a.student_prop
					FROM t_student_status a 
					WHERE a.stu_id = :studentId ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_studentProfile = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty( rs_studentProfile.student_prop );
			
			propAdvice.setAssist( true );
		
			sql = "UPDATE t_student_status a
					SET a.student_prop = :StudentProps 
					WHERE a.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentProps", value= propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
		}
		
	}

	/**
	* @hint "终止双学位修读资格"
	* 
	* @event "MachII Event Object"
	*/
	public void function stopStudentSecondDegree( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("STU");
		var studentAccessId = event.getArg("STUGRT");
		var sql = "";
		var queryObj = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 取消学生双学位选课授权*/
			
			sql = "UPDATE t_student_secdegree 
					SET stat = :CurrentStat 
					WHERE stusec_id = :studentAccessId ";
					
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentAccessId", value=studentAccessId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="CurrentStat", value="0", cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );
			
			var propAdvice = getstudentPropertyAdvice().init();
			
			sql = "SELECT a.student_prop
					FROM t_student_status a 
					WHERE a.stu_id = :studentId ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_studentProfile = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty( rs_studentProfile.student_prop );
			
			propAdvice.setSecondary( false );
			
			sql = "UPDATE t_student_status a
					SET a.student_prop = :StudentProps 
					WHERE a.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentProps", value= propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
		}

	}
	
	/**
	* @hint "取消双学位修读资格"
	* 
	* @event "MachII Event Object"
	*/
	public void function clearStudentSecondDegree( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("STU");
		var studentAccessId = event.getArg("STUGRT");
		var sql = "";
		var queryObj = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 取消学生双学位选课授权*/
			
			sql = "DELETE 
					FROM t_student_secdegree a 
					WHERE a.stusec_id = :studentAccessId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentAccessId", value=studentAccessId, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			
			var propAdvice = getstudentPropertyAdvice().init();
			
			sql = "SELECT a.student_prop
					FROM t_student_status a 
					WHERE a.stu_id = :studentId ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_studentProfile = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty( rs_studentProfile.student_prop );
			
			propAdvice.setSecondary( false );
			
			sql = "UPDATE t_student_status a
					SET a.student_prop = :StudentProps 
					WHERE a.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentProps", value= propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
		}

	}
	
	/**
	* @hint "恢复学生双学位资格"
	* 
	* @event "MachII Event Object"
	*/
	public void function openStudentSecondDegree( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("STU");
		var studentAccessId = event.getArg("STUGRT");
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 恢复学生双学位选课授权*/
		
			sql = "UPDATE t_student_secdegree 
					SET stat = :CurrentStat 
					WHERE stusec_id = :studentAccessId ";
					
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentAccessId", value=studentAccessId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="CurrentStat", value="1", cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );
			
			
			var propAdvice = getstudentPropertyAdvice().init();
		
			sql = "SELECT a.student_prop
					FROM t_student_status a 
					WHERE a.stu_id = :studentId ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_studentProfile = queryObj.execute( sql=sql ).getResult();
			
			
			propAdvice.parseProperty( rs_studentProfile.student_prop );
			
			propAdvice.setSecondary( true );
			
			sql = "UPDATE t_student_status a
					SET a.student_prop = :StudentProps 
					WHERE a.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentProps", value= propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
		}
		
	}	
	
	/**
	* @hint "将学生设置为提前毕业学籍"
	* 
	* @event "MachII Event Object"
	*/
	public void function addEarlyGraduate( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("STU");
		var sql = "";
		var queryObj = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var propAdvice = getstudentPropertyAdvice().init();
			
			sql = "SELECT a.student_prop
					FROM t_student_status a 
					WHERE a.stu_id = :studentId ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_studentProfile = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty( rs_studentProfile.student_prop );
			
			propAdvice.setEarlyGraduate( true );
			
			sql = "UPDATE t_student_status a
					SET a.student_prop = :StudentProps 
					WHERE a.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentProps", value= propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
		}
		
	}
	
	/**
	* @hint "将学生撤销提前毕业转为普通学籍"
	* 
	* @event "MachII Event Object"
	*/
	public void function removeEarlyGraduate( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("STU");
		var sql = "";
		var queryObj = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var propAdvice = getstudentPropertyAdvice().init();
			
			sql = "SELECT a.student_prop
					FROM t_student_status a 
					WHERE a.stu_id = :studentId ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			var rs_studentProfile = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty( rs_studentProfile.student_prop );
			
			propAdvice.setEarlyGraduate( false );
			
			sql = "UPDATE t_student_status a
					SET a.student_prop = :StudentProps 
					WHERE a.stu_id = :studentId ";
					
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="StudentProps", value= propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
		}
	}
	
	/**
	* @hint "班级添加学生"
	* 
	* @event "MachII Event Object"
	*/
	public void function addClassStudent( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("StudentID");
		var classId = event.getArg("classID");
		var sql = "";
		var queryObj = "";
		
		userProperty = sessionAdvice.getUserProps();
		
		var id = 0;
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/*限制班级重复添加*/
			sql = "SELECT * FROM i_stu_class_info WHERE cls_id = :classId AND stu_id = :studentId";
			
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="classId", value= classId, cfsqltype="cf_sql_varchar" );
			
			rs_stuClass = queryObj.execute( sql=sql ).getResult();
			
			/*限制学期班级重复添加*/
			sql = "SELECT b.cls_name, c.tch_name from i_stu_class_info a 
						 INNER JOIN t_class b ON b.cls_id = a.cls_id 
						 INNER JOIN t_teacher c ON c.tch_id = b.teacher_in_charge 
						 WHERE b.grade = (SELECT c.grade FROM t_class c WHERE c.cls_id = :classId ) 
							  AND 
							  a.stu_id = :studentId " ;
			 
			queryObj = new Query( datasource=application.dnsSlave ) ;
			queryObj.addParam( name="classId", value=classId, cfsqltype="cf_sql_varchar");
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar");
			 
			rs_classEntity = queryObj.execute( sql=sql ).getResult();
			
			
			if ( (rs_stuClass.recordCount eq 0) AND (rs_classEntity.recordCount eq 0) ){
			
				sql = "select id from (select * from i_stu_class_info t order by id desc) where rownum = 1 ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				
				var rs_stuCls = queryObj.execute( sql=sql ).getResult();
				
				id = rs_stuCls.id +1;
							
				sql = "INSERT INTO i_stu_class_info(
						id, stu_id, cls_id
					)values(
						:id,:studentId,:classId
					)";
				
				queryObj = new Query( datasource=application.dnsMaster );
				
				queryObj.addParam( name="id", value=id, cfsqltype="cf_sql_integer" );
				queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="classId", value= classId, cfsqltype="cf_sql_varchar" );
				
				queryObj.execute( sql=sql );
				
				
				/*刷新班级人数*/
				sql = "UPDATE t_class a SET a.cls_scale = (SELECT COUNT(*) from i_stu_class_info b where b.cls_id = a.cls_id) where cls_id = :classId";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="classId", value= classId, cfsqltype="cf_sql_varchar" );
				
				queryObj.execute( sql=sql );
				
				/*刷新学生入学班级信息*/
				sql = "UPDATE t_student a SET a.cls_id = :classId where a.stu_id = :studentId AND a.cls_id is null  ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				
				queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="classId", value= classId, cfsqltype="cf_sql_varchar" );
				
				queryObj.execute( sql=sql );
				
				/*刷新学生最近一个班级信息*/
				sql = "UPDATE t_student a SET a.class_id = :classId where a.stu_id = :studentId";
				
				queryObj = new Query( datasource=application.dnsMaster );
				
				queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="classId", value= classId, cfsqltype="cf_sql_varchar" );
				
				queryObj.execute( sql=sql );
				
				logFactory.clsAddStudent("4", userProperty["userName"] & " 给班级 " & event.getArg("className") & " 添加学生 " & event.getArg("studentName"),  studentId, classId);
			}
			
			var passArgs = structNew();
			structInsert( passArgs, "class", classId, true );

			event.setArgs( passArgs );
			
		}
		
	}
	
	/**
	* @hint "班级删除学生"
	* 
	* @event "MachII Event Object"
	*/
	public void function removeClassStudent( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("STU");
		var classId = event.getArg("class");
		var sql = "";
		var queryObj = "";
		
		userProperty = sessionAdvice.getUserProps();
		
		var id = 0;
		
		/* Every SQL operation is TRANSACATION*/
		transaction{
			
			sql = "SELECT * FROM i_stu_class_info WHERE stu_id = :studentId";
			
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			rs_stuClass = queryObj.execute( sql=sql ).getResult();
			
			/*删除学生*/			
			sql = "DELETE FROM i_stu_class_info WHERE cls_id = :classId AND stu_id = :studentId";
			
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="classId", value= classId, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			/*刷新班级人数*/
			 sql = "UPDATE t_class a SET a.cls_scale = (SELECT COUNT(*) from i_stu_class_info b where b.cls_id = a.cls_id) where cls_id = :classId";
			 
			 queryObj = new Query( datasource=application.dnsMaster );
			 queryObj.addParam( name="classId", value= classId, cfsqltype="cf_sql_varchar" );
			 
			 queryObj.execute( sql=sql );
			
			
			/*如果这是学生的第一个班级，那么删除学生的班级信息*/
			if ( rs_stuClass.recordCount eq 1){
				
				/*刷新学生入学班级信息*/
				sql = "UPDATE t_student a SET a.cls_id = '' where a.stu_id = :studentId ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				
				queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				
				queryObj.execute( sql=sql );
				
				/*刷新学生最近一个班级信息*/
				sql = "UPDATE t_student a SET a.class_id = '' where a.stu_id = :studentId";
				
				queryObj = new Query( datasource=application.dnsMaster );
				
				queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				
				queryObj.execute( sql=sql );
				
				
			}else{
				/*刷新学生最近一个班级信息*/
				sql = "UPDATE t_student t SET t.class_id = (
						   select cls_id from (
							  select a.stu_id, a.cls_id, b.grade 
							  from i_stu_class_info a 
							  INNER JOIN t_class b on b.CLS_ID  = a.cls_id 
							  WHERE a.stu_id = :studentId 
							  ORDER BY b.grade DESC 
						   ) m 
						   WHERE m.stu_id = t.stu_id 
						   AND rownum = 1
					) WHERE t.stu_id = :studentId ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				
				queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				
				queryObj.execute( sql=sql );
			}
			
			sql = "SELECT a.stu_name, b.cls_name FROM t_student a, t_class b WHERE b.cls_id = :classId AND a.stu_id = :studentId";
			
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="classId", value= classId, cfsqltype="cf_sql_varchar" );
			
			rs_studentClass = queryObj.execute( sql=sql ).getResult();
			
			
			logFactory.clsAddStudent("4", userProperty["userName"] & " 从班级 " & rs_studentClass.cls_name & " 删除学生 " & rs_studentClass.stu_name,  studentId, classId);
			
			var passArgs = structNew();
			structInsert( passArgs, "class", classId, true );

			event.setArgs( passArgs );
			
		}
		
	}
	
	/**
	* @hint "添加学分指导教师"
	* 
	* @event "MachII Event Object"
	*/
	public void function addTeacher( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("StudentID");
		var teacherId = event.getArg("tchID");
		
		var stuName = event.getArg("studentName");
		var tchName = event.getArg("tchName");
		var sql = "";
		var queryObj = "";
		
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "select t_teacher.tch_id, t_teacher.tch_name 
					FROM t_student 
					INNER JOIN t_teacher ON t_teacher.tch_id = t_student.tch_id 
					WHERE t_student.stu_id = :studentId";
				
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				
			var rs_student = queryObj.execute( sql=sql ).getResult();
			
			
			sql = "UPDATE t_student SET tch_id = :teacherId WHERE  stu_id = :studentId";
			
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="teacherId", value= teacherId, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			var content = "";
			
			if( rs_student.recordCount GT 0){
				content = "修改学分指导教师 " & rs_student.tch_name & "(" & rs_student.tch_Id & ") 为 " & tchName & "(" & teacherId & ")" ;
			}else{
				content = "添加学分指导教师 " & tchName & "(" & teacherId & ")";	
			}
		
			logFactory.writeLog("7", content,  studentId);
			
		}
		
		event.setArg( "TCHID", teacherId );
		
	}
	
	
	/**
	* @hint "删除学分指导教师"
	* 
	* @event "MachII Event Object"
	*/
	public void function removeStudentTeacher( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("STU");
		var stuName = event.getArg("stuName");
		
		var sql = "";
		var queryObj = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "UPDATE t_student SET tch_id = '' WHERE stu_id = :studentId ";
				
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				
			queryObj.execute( sql=sql );
		
			content = "学生 " & stuName & " 删除学分指导教师 ";
			
			logFactory.writeLog("7", content,  studentId);
			
		}
		
		event.setArg("TCHID", event.getArg("tchId"));
		
	}
	
	/**
	* @hint "添加论文指导教师"
	* 
	* @event "MachII Event Object"
	*/
	public void function addPaperTeacher( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("StudentID");
		var teacherId = event.getArg("tchID");
		
		var stuName = event.getArg("studentName");
		var tchName = event.getArg("tchName");
		var sql = "";
		var queryObj = "";
		
		userProperty = sessionAdvice.getUserProps();
	
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "select t_teacher.tch_id, t_teacher.tch_name 
					FROM t_student 
					INNER JOIN t_teacher ON t_teacher.tch_id = t_student.tch_id_paper  
					WHERE t_student.stu_id = :studentId";
				
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				
			var rs_student = queryObj.execute( sql=sql ).getResult();
			
			
			sql = "UPDATE t_student SET tch_id_paper = :teacherId WHERE  stu_id = :studentId";
			
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="teacherId", value= teacherId, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			var content = "";
			
			if( rs_student.recordCount GT 0){
				content = "修改论文指导教师 " & rs_student.tch_name & "(" & rs_student.tch_Id & ") 为 " & tchName & "(" & teacherId & ")" ;
			}else{
				content = "添加论文指导教师 " & tchName & "(" & teacherId & ")";	
			}
		
			logFactory.writeLog("9", content,  studentId);
			
		}
		
	}
	
	
	/**
	* @hint "删除论文指导教师"
	* 
	* @event "MachII Event Object"
	*/
	public void function removeStudentPaperTeacher( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("STU");
		var stuName = event.getArg("stuName");
		
		var sql = "";
		var queryObj = "";
		
		userProperty = sessionAdvice.getUserProps();
	
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "UPDATE t_student SET tch_id_paper = '' WHERE stu_id = :studentId ";
				
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				
			queryObj.execute( sql=sql );
		
			content = "学生 " & stuName & " 删除论文指导教师 ";
			
			logFactory.writeLog("9", content,  studentId);
			
		}
		
	}
	
	
	/**
	* @hint "添加学生论文信息"
	* 
	* @event "MachII Event Object"
	*/
	public void function addStuPaper( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("StudentId");
		var teacherId = event.getArg("teacherId");
		var tchId = event.getArg("tchId");
		var stuName = event.getArg("stuName");
		var tchName = event.getArg("teacherName");
		
		var title = event.getArg("paperTitle");
		var summary = event.getArg("paperSummary");
		var paperContent = event.getArg("paperContent");
		var gradTime = event.getArg("gradTime");
		var keywords = event.getArg("keywords");
		
		
		var sql = "";
		var queryObj = "";
		
		var content = "";
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "select 1 from t_paper where stu_id = :studentId";
				
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				
			var rs_paper = queryObj.execute( sql=sql ).getResult();
			
			if(title eq "" or summary eq ""){
				
				sql = "DELETE from t_paper where stu_id = :studentId";
					
				queryObj = new Query( datasource=application.dnsMaster );
				
				queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
					
				queryObj.execute( sql=sql );
				
				content = tchName & " 删除学生 " & stuName & " 毕业论文";
				
			}else{
				
				if( rs_paper.recordCount ){
					
					sql = "UPDATE t_paper SET tch_id = :teacherId, paper_title = :title,grad_date = :gradDate, paper_summary = :summary, paper_content = :paperContent,keywords = :keywords WHERE  stu_id = :studentId";
				
					queryObj = new Query( datasource=application.dnsMaster );
					
					queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="teacherId", value= tchId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="gradDate", value= gradTime, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="title", value= title, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="keywords", value= keywords, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="summary", value= summary, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="paperContent", value= paperContent, cfsqltype="cf_sql_clob" );
					
					queryObj.execute( sql=sql );	
					
					content = tchName & " 修改学生 " & stuName & " 毕业论文";
				}else{
					
					sql = "INSERT INTO t_paper(
								stu_id,paper_title,paper_summary,tch_id,grad_date, paper_content, keywords  
							)VALUES(
								:studentId, :title, :summary,:teacherId, :gradDate, :paperContent, :keywords 
							)";
				
					queryObj = new Query( datasource=application.dnsMaster );
					
					queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="teacherId", value= tchId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="title", value= title, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="summary", value= summary, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="gradDate", value= gradTime, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="paperContent", value= paperContent, cfsqltype="cf_sql_clob" );
					queryObj.addParam( name="keywords", value= keywords, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );		
					
					content = tchName & " 新增学生 " & stuName & " 毕业论文";
				}
				
			}
			
		
			logFactory.writeLog("10", content,  studentId);
			
		}
		
	}
	
	
	/**
	* @hint "修改学生论文信息（添加英文版）"
	* 
	* @event "MachII Event Object"
	*/
	public void function updateStuPaper( required MachII.framework.Event event ) output=false {
		
		var studentId = event.getArg("StudentId");
		var teacherId = event.getArg("teacherId");
		var stuName = event.getArg("stuName");
		var tchName = event.getArg("tchName");
		
		var title = event.getArg("paperTitleEnglish");
		var keywords = event.getArg("keywordsEnglish");
		var summary = event.getArg("paperSummaryEnglish");
		var paperContent = event.getArg("paperContentEnglish");
		
		
		var sql = "";
		var queryObj = "";
		
		var content = "";
		/* Every SQL operation is TRANSACATION*/
		transaction {
				
			sql = "UPDATE t_paper SET paper_title_english = :paperTitleEnglish, 
								 paper_summary_english = :paperSummaryEnglish, 
								 paper_content_english = :paperCoutentEnglish, 
								 keywords_english = :kerwordsEnglish WHERE  stu_id = :studentId";
		
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="paperTitleEnglish", value= title, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="paperSummaryEnglish", value= summary, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="paperCoutentEnglish", value= paperContent, cfsqltype="cf_sql_clob" );
			queryObj.addParam( name="kerwordsEnglish", value= keywords, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );	
			
			content = tchName & " 修改学生 " & stuName & " 毕业论文英文版";
		

			logFactory.writeLog("10", content,  studentId);
			
		}
		
	}
	
	
}

</cfscript>